package com.zr.serviceimpl;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zr.dao.UpdateDisstationDao;
import com.zr.model.Cdisstation;
import com.zr.model.Cstationtype;
import com.zr.model.Cuser;
import com.zr.service.UpdateDisstationService;

@Service("updateDisstationService")
public class UpdateDisstationServiceImpl<T> implements UpdateDisstationService<T>{

	@Resource
	private UpdateDisstationDao<T> updateDisstationDao;

	@Override
	public int getStataionExistsOrNot(String disname,int disid) {
		// TODO Auto-generated method stub
		return updateDisstationDao.getStataionExistsOrNot(disname,disid);
	}

	@Override
	public void updateStationByInfo(int disid, String disname, int uid,String cuname, int cuid,
			String disscope, Double disprice, int instation, String distype, String disstate) {
		Cdisstation ocd = updateDisstationDao.getOidStationInfoByDisid(disid);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		String time = sdf.format(date);
		StringBuffer infos = new StringBuffer();
		infos.append("编号为");
		infos.append(cuid);
		infos.append("的用户");
		infos.append(cuname);
		infos.append("在");
		infos.append(time);
		infos.append("修改了名称为");
		infos.append(disname);
		infos.append("的配送点");
		infos.append("原配送点的信息如下：");
		infos.append("原配送点的名称：");
		infos.append(ocd.getDisname()+",");
		infos.append("原配送点的类型：");
		infos.append(ocd.getCstationtype().getDistype()+",");
		infos.append("原配送点的状态：");
		infos.append(ocd.getCstationtype().getDisstate()+",");
		infos.append("原配送点的负责人ID：");
		infos.append(ocd.getCuser().getUid()+",");
		infos.append("原配送点的负责人ID名称：");
		infos.append(ocd.getCuser().getUname()+",");
		infos.append("原配送点的配送范围：");
		infos.append(ocd.getDisscope()+",");
		infos.append("原配送点的配送价格：");
		infos.append(ocd.getDisprice()+",");
		infos.append("原配送点的所属站点：");
		infos.append(ocd.getInstation()+",");
		String info = infos.toString();
		Cuser cuser = updateDisstationDao.getUserByInfo(cuid);
		Cstationtype cstationtype = updateDisstationDao.getStationTypeByInfo(distype, disstate);
		updateDisstationDao.updateStationByInfo(disid, disname, cuser, cstationtype, disscope, disprice, instation);
		updateDisstationDao.updateUserInfoByUid(uid, disid);
		updateDisstationDao.insertInfoIntoLog(time, cuname, cuid, info);
		
	}

	

}
